# encoding: utf-8
# @File  : test02.py
# @Author: wu shaofan
# @Date  :  2024/04/17
# @Desc :
import sys
sys.path.append('/var/jenkins_home/python3/lib/python3.8/site-packages')

import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By


# 设置 Chrome WebDriver 服务路径
driver_path = r'/var/jenkins_home/workspace/TPshop_webdemo_pro/chromedriver'
# 创建 ChromeOptions 对象
options = Options()
options.add_argument('--no-sandbox')
# 无头模式  "--headless"参数是不用打开图形界面
options.add_argument('--headless')
# 禁用gpu  不使用图形处理器来渲染页面
options.add_argument('--disable-gpu')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--start-maximized')
options.add_argument('--window-size=1920,1080')
# 添加默认端口
# options.add_argument('--remote-debugging-port=9222')
# 创建 Chrome WebDriver 服务
service = Service(driver_path)
# 创建 Chrome WebDriver 实例
driver = webdriver.Chrome(service=service, options=options)
# driver.maximize_window()cd
# 打开百度网页
driver.get("https://hmshop-test.itheima.net/Home/user/login.html")
driver.find_element(By.ID, "username").send_keys("18325530001")
driver.find_element(By.ID, "password").send_keys("wsf123456")
driver.find_element(By.ID, "verify_code").send_keys("8888")
driver.find_element(By.CSS_SELECTOR, ".J-login-submit").click()
time.sleep(1)
driver.find_element(By.LINK_TEXT, '返回商城首页').click()
driver.find_element(By.ID, 'q').send_keys("手机")
driver.find_element(By.CLASS_NAME, 'ecsc-search-button').click()
print('Success')
time.sleep(5)
print(driver.title)
driver.quit()